package com.authine.cloudpivot.ext.domain.vo;

import com.authine.cloudpivot.ext.dto.goods.VendorGoodsV1Entity;
import com.authine.cloudpivot.ext.utils.kingdee.DateUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.BeanUtils;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Created by Ezreal_Guo on 2019/4/26.
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel("供应商的商品物料")
public class VendorGoodsV1VO {
    //商品id
    @ApiModelProperty("商品id")
    private Long goodsId;
    @ApiModelProperty("品牌")
    private String brand;
    @ApiModelProperty("名称")
    private String name;
    @ApiModelProperty("型号")
    private String model;
    @ApiModelProperty("规格")
    private String spec;
    @ApiModelProperty("类目")
    private String category;
    @ApiModelProperty("销售单位")
    private String unit;
    @ApiModelProperty("包装内数量")
    private Double packageNum;
    @ApiModelProperty("包装单位")
    private String packageUnit;
    @ApiModelProperty("最小起订量")
    private Double minOrder;
    @ApiModelProperty("税率")
    private Double taxRate;
    @ApiModelProperty("未税单价")
    @Range(max = 2, message = "请填写正确单价")
    private Double pretaxPrice;
    @ApiModelProperty("含税单价")
    private Double price;
    @ApiModelProperty("库存数量")
    private Double stock;
    @ApiModelProperty("产地")
    private String place;
    @ApiModelProperty("发货地")
    private String deliveryPlace;
    @ApiModelProperty("交货期")
    private Integer delivery;
    @ApiModelProperty("保修期")
    private String warranty;
    @ApiModelProperty("sku编码")
    private String sku;
    @ApiModelProperty("条形码")
    private String barCode;
    @ApiModelProperty("金税编码")
    private String goldenTax;
    @ApiModelProperty("美国电子目录编码")
    private String unspsc;
    @ApiModelProperty("商品描述")
    private String description;
    @ApiModelProperty("运费比例")
    private Double freightRatio;
    @ApiModelProperty("技术参数")
    private String technical;
    @ApiModelProperty("包装参数")
    private String packaging;
    @ApiModelProperty("销售有效期")
    @JsonFormat(pattern = DateUtils.FORMAT_PATTERN_DATETIME)
    private Date expiry;
    @ApiModelProperty("长")
    private Double length;
    @ApiModelProperty("宽")
    private Double width;
    @ApiModelProperty("高")
    private Double height;
    @ApiModelProperty("重量")
    private Double weight;
    @ApiModelProperty("商品备注")
    private String memo;
    @ApiModelProperty("是否启用")
    private Boolean enabled;
    @ApiModelProperty("是否上架")
    private Boolean saled;
    @ApiModelProperty("货期要求")
    private String deliveryClaim;
    @ApiModelProperty("图片")
    private String images;
    @ApiModelProperty("供应商名称")
    private String orgFullname;
    @ApiModelProperty("上传时间")
    @JsonFormat(pattern = DateUtils.FORMAT_PATTERN_DATETIME)
    private Date time;
    @ApiModelProperty("类别")
    private String catalog;
    @ApiModelProperty("外部来源客户端id")
    private String clientId;
    @ApiModelProperty("外部来源商品id")
    private String clientGoodsId;
    @ApiModelProperty("是否为核心商品")
    private Boolean core;
    @ApiModelProperty("供应商id")
    private String vendorId;
//    private Integer safeStock;
//    private Integer stockDelivery;


    public static VendorGoodsV1VO v1EntityToV1VO(VendorGoodsV1Entity entity) {
        VendorGoodsV1VO vo = new VendorGoodsV1VO();
        BeanUtils.copyProperties(entity, vo);
        vo.setGoodsId(entity.getId());
        vo.setVendorId(entity.getVendorId().getId());
        return vo;
    }

    public static List<VendorGoodsV1VO> listV1ToListV1Vo(List<VendorGoodsV1Entity> entityList) {
        return entityList.stream().map(VendorGoodsV1VO::v1EntityToV1VO).collect(Collectors.toList());
    }

}
